#!/bin/bash

SRC="\
classic.html \
requirejs.html \
adm.html \
scripts/require.js \
scripts/main.js \
scripts/adm.js \
scripts/com/opentext/viewer.js \
scripts/com/opentext/document.js \
scripts/com/opentext/page.js \
scripts/com/opentext/modules/viewer.js \
scripts/com/opentext/modules/document.js \
scripts/com/opentext/modules/page.js"

echo "** Synchronize SVN Application OTCS Monitor **"

if [ -n "$1" ]; then
	echo -n "Detecting configuration ... "
else 
	echo "failed"
	echo "ERROR: no target destination set. Set target destination first and restart this tool"
	exit -1
fi

echo " OK"

#
# List all the files here ...
#
for file in $SRC
do
	echo -n "checking $file ... "
	if [ -f $file ]; then
		echo " OK"
	else
		echo " failed"
		echo "Perform svn checkout command first"
		exit -1
	fi
done

for file in $SRC; do
	TARGET="$1/$file"
	echo -n "copying $file ... "
	echo $TARGET
	if [ ! -d `dirname $TARGET` ]; then
   	mkdir -m 755 -p $(dirname $TARGET)
	fi
	`cp -f $file $1/$file`
	if [ -f "$1/$file" ]; then
		echo -n " "
	else
		echo " Copying failed"
		echo "Check the destination path $1 and permission to write there"
		exit -1
	fi
done

echo " OK"
